package com.spring_mysql_redis.config;

import com.spring_mysql_redis.timing.LikeTask;
import com.spring_mysql_redis.timing.MsgTask;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {

    private static final String LIKE_TASK_IDENTITY = "LikeTaskQuartz";
    private static final String MSG_TASK_IDENTITY = "msgTaskQuartz";


    @Bean
    public JobDetail quartzDetail(){
        return JobBuilder.newJob(LikeTask.class).withIdentity(LIKE_TASK_IDENTITY).storeDurably().build();
    }

    @Bean
    public JobDetail quartzDetail2(){
        return JobBuilder.newJob(MsgTask.class).withIdentity(MSG_TASK_IDENTITY).storeDurably().build();
    }

    @Bean
    public Trigger quartzTrigger(){
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInSeconds(10)  //设置时间周期单位秒
                .withIntervalInHours(2)  //两个小时执行一次(测试三分钟）
//                .withIntervalInMinutes(1)
                .repeatForever();
        return TriggerBuilder.newTrigger().forJob(quartzDetail())
                .withIdentity(LIKE_TASK_IDENTITY)
                .withSchedule(scheduleBuilder)
                .build();
    }
    @Bean
    public Trigger quartzTrigger2(){
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInSeconds(10)  //设置时间周期单位秒
                .withIntervalInHours(24*7)  //7天执行一次(测试三分钟）
//                .withIntervalInMinutes(1)
                .repeatForever();
        return TriggerBuilder.newTrigger().forJob(quartzDetail2())
                .withIdentity(MSG_TASK_IDENTITY)
                .withSchedule(scheduleBuilder)
                .build();
    }
}

